#include    <iostream>
#include    "Referee.h"

Referee::Referee(bool pos)
    : _victory(0)
{
    if (pos)
    {
        _players.push_back(new Player());
        _players.push_back(new Player());
    }
    else
    {
        _players.push_back(new Player());
        _players.push_back(new Player());
    }

    this->_board = Board::getInstance();
    this->_eat = new Eat();
}


char        Referee::play()
{
  int     nbPionPlaced = 0;
  int     maxPion = 19 * 19;
  int     playedPion = 0;

  for (int i = 0 ; !_victory && nbPionPlaced != maxPion ; ++i)
    {
      qDebug("Player is playing");
      playedPion = _players[i%2]->play();
      qDebug("Check if he's eating");
      this->_eat->doesEat(playedPion + ((i%2+1) << 16));
      if (!this->_eat->getBeg().size())
	++nbPionPlaced;
      else
	--nbPionPlaced;
      qDebug("let's place the player on the board");
      this->_board->setPlayerAt(i%2 + 1, (playedPion & 0xFF00) >> 8, playedPion & 0xFF);
      qDebug("let's display the board");
      this->_board->display();
    }
  return _victory;
}
